// #include "Rt_ModeCode_intr_config_inc.h"
#include "Rt_ModeCode_intr_config.h"
void rt_ModeCode_intr_config(XRt1553B *InstancePtr)
{
    u8 *ptr = (u8 *)&(InstancePtr->ModeCode_cfg); // ptr[i]按顺序指向结构体每个元素
    u32 foo = 0;
    // 未定义的方式指令和广播发送指令均置0
    XRt1553B_WriteMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_RX_LSB_OFFSET, 0);
    XRt1553B_WriteMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_BCSTTX_LSB_OFFSET, 0);
    XRt1553B_WriteMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_BCSTTX_MSB_OFFSET, 0);
    // 其他地址清零 作为初始化
    XRt1553B_WriteMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_RX_MSB_OFFSET, 0);
    XRt1553B_WriteMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_TX_LSB_OFFSET, 0);
    XRt1553B_WriteMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_TX_MSB_OFFSET, 0);
    XRt1553B_WriteMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_BCSTRX_LSB_OFFSET, 0);
    XRt1553B_WriteMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_BCSTRX_MSB_OFFSET, 0);

    // 处理无数据字的发送方式指令 共计9个中断 对应地址010AH 发送方式字0--15
    for (u32 i = 0; i < 9; i++)
    {
        if (ptr[i] == XRT53_MODECODE_INTR_ENABLE) // 中断使能
        {
            foo = XRt1553B_ReadMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_TX_LSB_OFFSET);
            XRt1553B_SET_BIT(foo, i);
            XRt1553B_WriteMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_TX_LSB_OFFSET, foo);
        }
    }

    // 发送矢量字
    if (XRT53_MODECODE_INTR_ENABLE == InstancePtr->ModeCode_cfg.TransVector_IntrEnable)
    {
        foo = XRt1553B_ReadMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_TX_MSB_OFFSET);
        XRt1553B_SET_BIT(foo, XRT53_MODECODE_INTR_LOC_TRANS_VECTOR);
        XRt1553B_WriteMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_TX_MSB_OFFSET, foo);
    }

    // 带字同步
    if (XRT53_MODECODE_INTR_ENABLE == InstancePtr->ModeCode_cfg.SyncwithData_IntrEnable)
    {
        foo = XRt1553B_ReadMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_RX_MSB_OFFSET);
        XRt1553B_SET_BIT(foo, XRT53_MODECODE_INTR_LOC_SYNC_WITH_DATA);
        XRt1553B_WriteMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_RX_MSB_OFFSET, foo);
    }

    // 发送上一命令字
    if (XRT53_MODECODE_INTR_ENABLE == InstancePtr->ModeCode_cfg.TransLastCommand_IntrEnable)
    {
        foo = XRt1553B_ReadMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_TX_MSB_OFFSET);
        XRt1553B_SET_BIT(foo, XRT53_MODECODE_INTR_LOC_TRANS_LASR_CMD);
        XRt1553B_WriteMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_TX_MSB_OFFSET, foo);
    }

    // 发送自测试
    if (XRT53_MODECODE_INTR_ENABLE == InstancePtr->ModeCode_cfg.TransBIT_IntrEnable)
    {
        foo = XRt1553B_ReadMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_TX_MSB_OFFSET);
        XRt1553B_SET_BIT(foo, XRT53_MODECODE_INTR_LOC_TRANS_BIT_WORD);
        XRt1553B_WriteMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_TX_MSB_OFFSET, foo);
    }

    // 选定的发送器关闭
    if (XRT53_MODECODE_INTR_ENABLE == InstancePtr->ModeCode_cfg.SelTransmitterShutdown_IntrEnable)
    {
        foo = XRt1553B_ReadMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_RX_MSB_OFFSET);
        XRt1553B_SET_BIT(foo, XRT53_MODECODE_INTR_LOC_SEL_TX_SHUTDOWN_ENABLE);
        XRt1553B_WriteMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_RX_MSB_OFFSET, foo);
    }

    // 取消选定的发送器关闭
    if (XRT53_MODECODE_INTR_ENABLE == InstancePtr->ModeCode_cfg.OverrideSelTransmitterShutdown_IntrEnable)
    {
        foo = XRt1553B_ReadMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_RX_MSB_OFFSET);
        XRt1553B_SET_BIT(foo, XRT53_MODECODE_INTR_LOC_SEL_TX_SHUTDOWN_DISABLE);
        XRt1553B_WriteMem(InstancePtr->BaseAddress, XRT53_MODECODE_INTR_RX_MSB_OFFSET, foo);
    }

    return;
}